﻿/*
 * ********************************************************************************************************************
 *
 *               iFHS7.
 *              ;BBMBMBMc                  rZMBMBR              BMB
 *              MBEr:;PBM,               7MBMMEOBB:             BBB                       RBW
 *     XK:      BO     SB.     :SZ       MBM.       c;;     ir  BBM :FFr       :SSF:    ;xBMB:r   iuGXv.    i:. iF2;
 *     DBBM0r.  :D     S7   ;XMBMB       GMBMu.     MBM:   BMB  MBMBBBMBMS   WMBMBMBBK  MBMBMBM  BMBRBMBW  .MBMBMBMBB
 *      :JMRMMD  ..    ,  1MMRM1;         ;MBMBBR:   MBM  ;MB:  BMB:   MBM. RMBr   sBMH   BM0         UMB,  BMB.  KMBv
 *     ;.   XOW  B1; :uM: 1RE,   i           .2BMBs  rMB. MBO   MBO    JMB; MBB     MBM   BBS    7MBMBOBM:  MBW   :BMc
 *     OBRJ.SEE  MRDOWOR, 3DE:7OBM       .     ;BMB   RMR7BM    BMB    MBB. BMB    ,BMR  .BBZ   MMB   rMB,  BMM   rMB7
 *     :FBRO0D0  RKXSXPR. JOKOOMPi       BMBSSWBMB;    BMBB:    MBMB0ZMBMS  .BMBOXRBMB    MBMDE RBM2;SMBM;  MBB   xBM2
 *         iZGE  O0SHSPO. uGZ7.          sBMBMBDL      :BMO     OZu:BMBK,     rRBMB0;     ,EBMB  xBMBr:ER.  RDU   :OO;
 *     ,BZ, 1D0  RPSFHXR. xWZ .SMr                  . .BBB
 *      :0BMRDG  RESSSKR. 2WOMBW;                   BMBMR
 *         i0BM: SWKHKGO  MBDv
 *           .UB  OOGDM. MK,                                          Copyright (c) 2015-2019.  斯伯坦机器人
 *              ,  XMW  ..
 *                  r                                                                     All rights reserved.
 *
 * ********************************************************************************************************************
 */

using MongoDB.Driver;
using Sybotan.Base;
using System.ComponentModel;
using System.Windows;

namespace MongoPI
{
    /// <summary>
    /// CollectionAddDialog.xaml 的交互逻辑
    /// </summary>
    public partial class CollectionAddDialog : Window, INotifyPropertyChanged
    {
        /// <summary>
        /// 实现INotifyPropertyChanged接口
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #region 定义属性
        /// <summary>
        /// 服务名
        /// </summary>
        private string mCollectionName = "";
        public string CollectionName
        {
            get => mCollectionName;
            set
            {
                mCollectionName = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CollectionName)));
            }
        }

        /// <summary>
        /// 创建集合选项
        /// </summary>
        public CreateCollectionOptions Options = new CreateCollectionOptions();

        /// <summary>
        /// 封顶集合
        /// </summary>
        public bool Capped
        {
            get => Options.Capped.GetValueOrDefault();
            set
            {
                Options.Capped = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Capped)));
            }
        }

        /// <summary>
        /// 最大字节数
        /// </summary>
        public long MaxSize
        {
            get => Options.MaxSize.GetValueOrDefault();
            set
            {
                Options.MaxSize = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MaxSize)));
            }
        }

        /// <summary>
        /// 最大文档数
        /// </summary>
        public long MaxDocuments
        {
            get => Options.MaxDocuments.GetValueOrDefault();
            set
            {
                Options.MaxDocuments = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MaxDocuments)));
            }
        }

        /// <summary>
        /// 自动生成_id
        /// </summary>
        public bool AutoIndexId
        {
            get => Options.AutoIndexId.GetValueOrDefault();
            set
            {
                Options.AutoIndexId = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(AutoIndexId)));
            }
        }

        /// <summary>
        /// NoPadding
        /// </summary>
        public bool NoPadding
        {
            get => Options.NoPadding.GetValueOrDefault();
            set
            {
                Options.NoPadding = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(NoPadding)));
            }
        }

        /// <summary>
        /// UsePowerOf2Sizes
        /// </summary>
        public bool UsePowerOf2Sizes
        {
            get => Options.UsePowerOf2Sizes.GetValueOrDefault();
            set
            {
                Options.UsePowerOf2Sizes = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(UsePowerOf2Sizes)));
            }
        }
        #endregion

        /// <summary>
        /// 添加集合窗口构造函数
        /// </summary>
        public CollectionAddDialog()
        {
            InitializeComponent();
            DataContext = this;
            AutoIndexId = true;

            return;
        } // Function CollectionAddDialog()

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender">事件发起者</param>
        /// <param name="e">事件参数</param>
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(Options.ToJson());
            DialogResult = true;
            return;
        } // Function ButtonAdd_Click()
    } // class CollectionAddDialog
} // Namespace MongoPI
